package sphere.view;
import java.awt.*;
import java.awt.event.*;

import sphere.controller.SphereController;

public class SphereWindow extends Frame {

	private static final long serialVersionUID = 6317841864270798958L;
	
	private TextField radiusTextField;
	private TextField volumeTextField;
	private TextField surfaceTextField;

	protected class PrivListener extends WindowAdapter{
		
		public void windowClosing (WindowEvent e){
			System.exit(0);
		}
	}
	
	public SphereWindow(String title)
	{
		this.setResizable(false);
		this.setLocation(100, 100);
		Panel monPanel = new Panel(new GridLayout(0,2,10,10));
		Dimension dim = new Dimension();
		dim.setSize(500, 100);
		monPanel.setPreferredSize(dim);
		monPanel.add(new Label("Radius = "));
		radiusTextField = new TextField();
		monPanel.add(radiusTextField);
		monPanel.add(new Label("Volume = "));
		volumeTextField = new TextField();
		volumeTextField.setText("0");
		volumeTextField.setEditable(false);
		monPanel.add(volumeTextField);
		monPanel.add(new Label("Surface area = "));
		surfaceTextField = new TextField();
		surfaceTextField.setText("0");
		surfaceTextField.setEditable(false);
		monPanel.add(surfaceTextField);
		this.add(monPanel);
		PrivListener monListener = new PrivListener();
		this.addWindowListener(monListener);
		
		SphereController monListenerBis = new SphereController(this);
		radiusTextField.addKeyListener(monListenerBis);
		
		this.pack();
	}
	
	public void setRadiusTextFieldValue(String text){
		
		this.radiusTextField.setText(text);
		
	}
	public String getRadiusTextFieldValue(){
		
		return this.radiusTextField.getText();
		
	}
	public void setRadiusTextFieldColor(Color c){
		
		this.radiusTextField.setBackground(c);
		
	}
	
	public void setVolumeTextFieldValue(String text){
		
		this.volumeTextField.setText(text);
		
	}
	public String getVolumeTextFieldValue(){
		
		return this.volumeTextField.getText();
		
	}
	public void setSurfaceTextFieldValue(String text){
		
		this.surfaceTextField.setText(text);
		
	}
	public String getSurfaceTextFieldValue(){
		
		return this.surfaceTextField.getText();
		
	}
}
